﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FTPC {
    public delegate void StateChange(object sender, EventArgs e);

    public class UpLoadJob {
        public string localpath;
        public string filename;
        public long filesize;
        private JobState state;
        public event StateChange stateChange;


        public void setState(JobState state) {
            JobState tmp = this.state;
            this.state = state;
            if (tmp != state) {
                this.stateChange (this, null);
            }
        }

        public UpLoadJob(string localpath, string filename, long filesize) {
            this.filename = filename;
            this.localpath = localpath;
            this.filesize = filesize;
            this.state = JobState.NULL;
        }

        public override string ToString() {
            return this.filename + " " + getStateStr ( );
        }

        /// <summary>
        /// 文件上传状态
        /// </summary>
        /// <returns></returns>
        public string getStateStr() {
            switch (this.state) {
                case JobState.CREATE:
                    return "等待上传";
                case JobState.ERROR:
                    return "上传错误";
                case JobState.UPLOADED:
                    return "上传完毕";
                case JobState.UPLOADING:
                    return "上传中...";
                case JobState.MD5:
                    return "正在校验文件";
            }
            return "未知状态";
        }
    }

    public enum JobState {
        CREATE = 1,
        UPLOADING = 2,
        UPLOADED = 3,
        ERROR = 4,
        MD5 = 5,
        NULL = 0,
    }
}
